#include "PythonErrorHandler.h"

PythonErrorHandler::PythonErrorHandler():
    QObject(),
    _errorCount(0)
{
}

PythonErrorHandler::~PythonErrorHandler()
{
}

void PythonErrorHandler::handleUnexpectedToken(int /*expectedKind*/, const QString & expectedToken, const TokenPtr& actual, PythonGrammar30 */*parser*/)
{
    _errorCount++;
    emit error(QString("Expecting %1 at: %2:%3 but got %4\n").arg(expectedToken).arg(actual->beginLine).arg(actual->beginColumn).arg(actual->image), actual->beginLine, actual->beginColumn);
}

void PythonErrorHandler::handleParseError(const TokenPtr&/*last*/, const TokenPtr& unexpected, const JAVACC_STRING_TYPE & production, PythonGrammar30 */*parser*/)
{
    _errorCount++;
    fprintf(stderr, "Encountered: %s at: %d:%d while parsing: %s\n", qPrintable(unexpected->image), unexpected->beginLine, unexpected->beginColumn, qPrintable(production));
}

int PythonErrorHandler::getErrorCount()
{
    return _errorCount;
}
